package com.yuanfeng.action.front.pay;

import com.opensymphony.xwork2.ActionSupport;
import com.yuanfeng.util.PaymentUtil;
import org.apache.struts2.ServletActionContext;

import javax.servlet.http.HttpServletRequest;

/**
 * 用户下单成功的支付Action
 * Created by yuanfeng on 2019/5/8 8:39
 */
public class PayAction extends ActionSupport {

    public String payGoods() {

        HttpServletRequest request = ServletActionContext.getRequest();
        String p0_Cmd = "Buy";
        String p1_MerId = "10001126856";
        String p2_Order = request.getParameter("orderNo");
        String p3_Amt = request.getParameter("amt");
        String p4_Cur = "CNY";
        String p5_Pid = "";
        String p6_Pcat = "";
        String p7_Pdesc = "";
        String p8_Url = "/result_payResult.action";//成功之后处理页面
        String p9_SAF = "";
        String pa_MP = "";
        String pd_FrpId = request.getParameter("bank");//支付的银行
        String pr_NeedResponse = "0";
        //对交易数据进行hmac加密
        String hmac = PaymentUtil.buildHmac(
                p0_Cmd,
                p1_MerId,
                p2_Order,
                p3_Amt,
                p4_Cur,
                p5_Pid,
                p6_Pcat,
                p7_Pdesc,
                p8_Url,
                p9_SAF,
                pa_MP,
                pd_FrpId,
                pr_NeedResponse,
                "69cl522AV6q613Ii4W6u8K6XuW8vM1N6bFgyv769220IuYe9u37N4y7rI4Pl");

        //把要发送的参数先转到jsp页面中，再从jsp页面中提交请求到易宝

        request.setAttribute("p0_Cmd", p0_Cmd);
        request.setAttribute("p1_MerId", p1_MerId);
        request.setAttribute("p2_Order", p2_Order);
        request.setAttribute("p3_Amt", p3_Amt);
        request.setAttribute("p4_Cur", p4_Cur);
        request.setAttribute("p5_Pid", p5_Pid);
        request.setAttribute("p6_Pcat", p6_Pcat);
        request.setAttribute("p7_Pdesc", p7_Pdesc);
        request.setAttribute("p8_Url", p8_Url);
        request.setAttribute("p9_SAF", p9_SAF);
        request.setAttribute("pa_MP", pa_MP);
        request.setAttribute("pd_FrpId", pd_FrpId);
        request.setAttribute("pr_NeedResponse", pr_NeedResponse);
        request.setAttribute("hmac", hmac);
        return "payGoods";
    }
}
